# -*- coding: utf-8 -*-
# !/usr/bin/env python
# @ author = 'zoushunli'
# @ author_email = '409358374@qq.com'
import sys
import zipfile
import rarfile
import threading
import datetime
import os
import subprocess
import getopt


i = 0
fileGet = ''

class MyThread(threading.Thread):
    def __init__(self, func, args, name=''):
        super(MyThread, self).__init__()

        self.name = name
        self.func = func
        self.args = args
        self.result = self.func(*self.args)

    def getResult(self):
        try:
            return self.result
        except Exception:
            return None


def extractFile(fileExt, password, fileType):
    try:
        encodestr = str.encode(password)
        if fileType == 'zip':
             fileExt.extractall(pwd=encodestr)
        else:
            fileExt.extractall(pwd=password)
        global i
        i += 1
        print('search count: %d, real password is : %s' % (i, password))
    except:
        i += 1
        print("search count : %d,test password : %s, err:%s" % (i, password, sys.exc_info()[0]))
        pass

def main():
    path = r'E:\BaiduYunDownload\Maya渲染系统设置技巧视频教程.rar'.replace('\\', '/')
    # path = input("please input path:").replace('\\', '/')
    
    fileType = os.path.splitext(path)[-1][1:]
    pwdLists = open(r'E:\scripts\password.txt', 'r')
    startTime = datetime.datetime.now()
    fileGet = rarfile.RarFile(path)
    try:
        for line in pwdLists.readlines():
            passworld = line.strip('\n')
            t = MyThread(extractFile, (fileGet, passworld, fileType))
            t.start()
            if (t.getResult() is passworld):
                print('passworld is :', line)
                break
        endTime = datetime.datetime.now()
        timeSpan = endTime - startTime
        print("search time:%ss" % (timeSpan.total_seconds()))
    except :
        print("err:%s" % sys.exc_info()[0])

if __name__ == '__main__':
    print(ord('A'))

    print([i for i in range(10)])

    num = [i for i in range(10)]
    lowerStr = [chr(i) for i in range(65, 91)]
    upStr = [chr(i) for i in range(95, 123)]
    main()